/**
 * @Author:  renyc
 * @Date: 2022-11-30 20:13:36
 */

import * as Cesium from 'cesium/Cesium';
import OneSISImageryProvider from './provider/OneSISImageryProvider';
import GPlatesImageryProvider from './provider/GPlatesImageryProvider';
import ImageryType from './ImageryType';

class ImageryFactory{

    /**
     * 创建XYZ格式的Imagery图层
     * {
     *      url: 'http://<host>/{z}/{x}/{y}.png'
     * }
     * @param {*} options 
     * @returns {module:cesium.UrlTemplateImageryProvider}
     */
    static createXYZImageryProvider(options){
        return new Cesium.UrlTemplateImageryProvider(options)
    }

    /**
     * 创建OGC WMS类型的Imagery图层
     * @param {*} options 
     * @returns 
     */
    static createWebMapServiceImageryProvider(options){
        return new Cesium.WebMapServiceImageryProvider(options);
    }

    /**
     * 创建OGC WMTS类型的Imagery图层
     * @param {} options 
     */
    static createWebMapTileServiceImageryProvider(options){
        return new Cesium.WebMapTileServiceImageryProvider(options);
    }

    /**
     * 创建ArcGIS的ImageryProvider
     * @param {*} options 
     * {
     *      url : 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
     * }
     * @returns {module:cesium.ArcGisMapServerImageryProvider}
     */
    static createArcGISImageryProvider(options){
        const url = 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer';
        if(!options){
            options = {url};
        }
        else{
            if(!options.url){
                options.url = url;
            }
        }
        return new Cesium.ArcGisMapServerImageryProvider(options);
    }

    /**
     * 创建ArcGIS的OpenStreetMapImageryProviderr
     * @param  {*} options 
     * {
     *      url : 'https://a.tile.openstreetmap.org/'
     * }
     * @returns {module:cesium.OpenStreetMapImageryProvider}
     */
    static createOpenStreetImageryProvider(options){
        const url = 'https://a.tile.openstreetmap.org/';
        if(!options){
            options = {url};
        }
        else{
            if(!options.url){
                options.url = url;
            }
        }
        return new Cesium.OpenStreetMapImageryProvider(options);
    }

    /**
     * 创建MapBox的ImageryProvider
     * @param  {*} options 
     * @returns {module:cesium.MapboxImageryProvider}
     */
    static createMapboxImageryProvider(options){
        return new Cesium.MapboxImageryProvider(options);
    }

    /**
     * 创建OneSIS的ImageryProvider
     * @param {*} options 
     * @returns {module:OneSISImageryProvider}
     */
    static createOneSISImageryProvider(options){
        return new OneSISImageryProvider(options);
    }

    static createGPlatesImageryProvider(options){        
        return new GPlatesImageryProvider(options);
    }

    static createImageryProvider(type, options){
        let provider = undefined;
        switch(type){
            case ImageryType.ARCGIS:{
                provider = this.createArcGISImageryProvider(options);
                break;
            }
            case ImageryType.MAPBOX:{
                provider = this.createMapboxImageryProvider(options);
                break;
            }
            case ImageryType.ONESIS:{
                provider = this.createOneSISImageryProvider(options);
                break;
            }
            case ImageryType.OSM:{
                provider = this.createOpenStreetImageryProvider(options);
                break;
            }
            case ImageryType.GPLATES:
                provider  = this.createGPlatesImageryProvider(options);
                break;
        }
        return provider;
    }
}

export default ImageryFactory